package com.example.easybuy.service.impl;

import com.example.easybuy.mapper.EasybuyNewsMapper;
import com.example.easybuy.pojo.EasybuyNews;
import com.example.easybuy.service.EasybuyNewsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 张子晨
 * @since 2021-03-12
 */
@Service
public class EasybuyNewsServiceImpl implements EasybuyNewsService {

    @Autowired
    EasybuyNewsMapper easybuyNewsMapper;

    //查询最新的5条新闻
    @Override
    public List<EasybuyNews> newsLatest() {
        return easybuyNewsMapper.newsLatest();
    }

    //分页查询所有新闻
    @Override
    public PageInfo<EasybuyNews> newsAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<EasybuyNews> list = easybuyNewsMapper.newsAll();
        PageInfo<EasybuyNews> pageInfo = new PageInfo<EasybuyNews>(list);
        return pageInfo;
    }

    //根据id查询新闻
    @Override
    public EasybuyNews getNewsById(int id) {
        return easybuyNewsMapper.getNewsById(id);
    }
}
